<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="root" value="${pageContext.request.contextPath}"/>
<html>

	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1">
		<!-- Google Chrome Frame也可以让IE用上Chrome的引擎: -->
		<meta name="renderer" content="webkit">
		<!--国产浏览器高速模式-->
		<meta name="viewport" content="width=device-width, initial-scale=1">

		<!-- 公共样式 开始 -->
		<link rel="stylesheet" type="text/css" href="${root}/css/base.css">
		<link rel="stylesheet" type="text/css" href="${root}/css/iconfont.css">
		<script type="text/javascript" src="${root}/framework/jquery-1.11.3.min.js"></script>
		<link rel="stylesheet" type="text/css" href="${root}/layui/css/layui.css">
		<script type="text/javascript" src="${root}/layui/layui.js"></script>
		<!-- 滚动条插件 -->
		<link rel="stylesheet" type="text/css" href="${root}/css/jquery.mCustomScrollbar.css">
		<script src="${root}/framework/jquery-ui-1.10.4.min.js"></script>
		<script src="${root}/framework/jquery.mousewheel.min.js"></script>
		<script src="${root}/framework/jquery.mCustomScrollbar.min.js"></script>
		<script src="${root}/framework/cframe.js"></script><!-- 仅供所有子页面使用 -->
		<script src="${root}/js/singup.js"></script>
		<!-- 公共样式 结束 -->
		
		<style>
			.layui-form{
				margin-right: 30%;
			}
		</style>
	</head>
	<body>
		<div class="cBody">
			<form id="addForm" class="layui-form" action="${root}/admin/Agent_add" >
				<div class="layui-form-item">
					<label class="layui-form-label">管理员名称</label>
					<div class="layui-input-inline shortInput">
						<input type="text" id="admin_name" name="admin_name" required lay-verify="required|ZHCheck" placeholder="只允许输入中文" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">地区</label>
	                <div class="layui-input-inline">
	                    <select name="provid" id="provid" lay-filter="provid">
	                    </select>
	                </div>
	                <div class="layui-input-inline">
	                    <select name="cityid" id="cityid" lay-filter="cityid">
	                        <option value="">请选择市</option>
	                    </select>
	                </div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">登录名</label>
					<div class="layui-input-inline shortInput">
						<input type="text" id="login_name" name="login_name" required lay-verify="required"  autocomplete="off" class="layui-input" ><span id="namespan"></span>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">登录密码</label>
					<div class="layui-input-inline shortInput">
						<input type="password" id="password" name="password" required lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">确认密码</label>
					<div class="layui-input-inline shortInput">
						<input type="password" id="repassword" name="repassword" required lay-verify="required" autocomplete="off" class="layui-input"onblur="return check_repassword()"><span id="re_news"></span>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">电话</label>
					<div class="layui-input-inline shortInput">
						<input type="text" id="telephone" name="telephone" required lay-verify="required|phone" placeholder="例：13000000000" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">邮箱</label>
					<div class="layui-input-inline shortInput">
						<input type="text" id="email" name="email" required lay-verify="required|NEWEmail" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">是否开通</label>
					<div class="layui-input-block" >
						<input type="radio" id="types" name="types" value="1" title="启用">
					</div>
				</div>
				
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn" lay-submit lay-filter="submitBut" type="button" onclick="agent_add()">立即提交</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
			</form>
			
			<!-- 三级省市 插件 -->
    		<script src="${root}/framework/area.js"></script>
			<script src="${root}/framework/province.js"></script>
			<script>
				//默认城市为：浙江 - 温州
		        var defaults = {
		            s1: 'provid',
		            s2: 'cityid',
		            s3: 'areaid',
		            v1: 330000,
		            v2: 330300,
		            v3: null
		        };
			</script>
			<script>
				function agent_add() {
                    var admin_name = $("#admin_name").val();
                    var login_name = $("#login_name").val();
                    var password = $("#password").val();
                    var repassword = $("#repassword").val();
                    var namespan =$("#namespan").html();
                    var telephone = $("#telephone").val();
                    var email = $("#email").val();
                    if (admin_name == null || admin_name == "") {
                        return false;
                    }
                    if (login_name == null || login_name == "") {
                        return false;
                    }
                    if(namespan == "<font color=\"red\">用户名已被使用</font>")
                    {
                        return false;
                    }
                    if (password == null || password == "") {
                        return false;
                    }
                    if (repassword == null || repassword == "") {
                        return false;
                    }
                    if(password != repassword)
                    {
                        return false;
                    }
                    if (telephone == null || telephone == "") {
                        return false;
                    }
                    if (email == null || email == "") {
                        return false;
                    }
					$.ajax({
						url:"${root}/admin/Agent_add",
						type:"POST",
						contentType:"application/json",
						data:JSON.stringify({admin_name:admin_name,
							cityid:$("#cityid").val(),
							login_name:login_name,
							password:password,
							telephone:telephone,
							email:email,
							types:$("#types").val()
						}),
						dataType:"json",
						success:function (resp) {
							alert(resp.message);
							if(resp.data == 0)
							{
								window.location.href="/admin/agent_list";
							}
						},
						error:function (resp) {
							alert(resp.message);
						}
					})
				}
			</script>
		</div>
	</body>

</html>